﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AnnotateMe.Interfaces
{
    public class LineSegmentConnector : Connector
    {
        private readonly ImmutablePoint startPoint, endPoint;
        private readonly Action<ImmutablePoint, ImmutablePoint> draw;

        public LineSegmentConnector(ImmutablePoint startPoint, ImmutablePoint endPoint, Action<ImmutablePoint, ImmutablePoint> draw)
        {
            this.startPoint = startPoint;
            this.endPoint = endPoint;
            this.draw = draw;
        }

        public override void Draw()
        {
            this.draw(this.StartPoint, this.EndPoint);
        }

        public override ImmutableRectangle GetContainingRectangle()
        {
            return new ImmutableRectangle(
                this.StartPoint,
                new ImmutableSize(Math.Abs(this.StartPoint.X - this.EndPoint.X), Math.Abs(this.StartPoint.Y - this.EndPoint.Y)), 
                (_) => { }); 
        }

        public override Shape MoveBy(double deltaX, double deltaY)
        {
            return new LineSegmentConnector(
                new ImmutablePoint(this.startPoint.X + deltaX, this.startPoint.Y + deltaY),
                new ImmutablePoint(this.endPoint.X + deltaX, this.endPoint.Y + deltaY),
                this.draw);
        }

        public ImmutablePoint StartPoint { get { return this.startPoint; } }
        public ImmutablePoint EndPoint { get { return this.endPoint; } }
    }
}
